package diershiyiti;

import java.io.*;
import java.util.*;

/*
要求按照成绩总分从高到低写入文本文件，最后在从文件中把读取数据显示在控制台
格式：姓名,语文成绩,数学成绩,英语成绩 举例：林青霞,98,99,100
 */
public class Demo {
    public static void main(String[] args) throws IOException {
        ArrayList<ChengJi>list=new ArrayList<>();
        for (int i=1;i<=3;i++) {
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入第"+i+"学生信息");
            System.out.println();
            System.out.println("姓名");
            String next = sc.next();
            System.out.println("语文成绩");
            int i1 = sc.nextInt();
            System.out.println("数学成绩");
            int i2 = sc.nextInt();
            System.out.println("英语成绩");
            int i3 = sc.nextInt();
            ChengJi chengJi=new ChengJi(next,i1,i2,i3);
            list.add(chengJi);
        }
        BufferedWriter br=new BufferedWriter(new FileWriter("tianzhenyuan\\a.txt"));
        System.out.println("数据写入文件完毕");
        System.out.println("文件中的数据展示如下:");
        System.out.println("姓名,语文成绩,数学成绩,英语成绩");
        for (ChengJi chengJi : list) {
            br.write(chengJi.toString());
            br.newLine();
            System.out.println(chengJi);
        }
        br.close();
    }
}
